<template>
  <div class="goods-number">
    <a @click="changeNum(0)" href="javascript:;" :class="{jy:value===min}">-</a>
    <input type="text" :value="value" readonly />
    <a @click="changeNum(1)" href="javascript:;" :class="{jy:value===max}">+</a>
  </div>
</template>

<script>
export default {
  name: 'goods-number',
  props: {
    value: {
      type: Number,
      default: 1
    },
    min: {
      type: Number,
      default: 1
    },
    max: {
      type: Number,
      default: 100
    }
  },
  methods: {
    changeNum (type) {
      if (type === 0) {
        if (this.value <= this.min) return
        this.$emit('input', this.value - 1)
        this.$emit('change', this.value - 1)
      } else {
        if (this.value >= this.max) return
        this.$emit('input', this.value + 1)
        this.$emit('change', this.value + 1)
      }
    }
  }
}
</script>

<style scoped lang='less'>
.goods-number {
  width: 116px;
  height: 28px;
  border: 1px solid #e4e4e4;
  display: flex;
  input {
    border-left: 1px solid #e4e4e4;
    border-right: 1px solid #e4e4e4;
    width: 60px;
    line-height: 26px;
    text-align: center;
    color: #666;
  }
  a {
    width: 28px;
    text-align: center;
    line-height: 26px;
    color: #999;
    font-size: 18px;
    &.jy {
      cursor: not-allowed;
      color: #ccc;
    }
  }
}
</style>
